import {reqGoodsDetailInfo} from '@/api/index'

const state ={
    //商品详情信息
    goodsDetailInfo:{}
}
const mutations={
    //商品详情信息
    RECEIVE_GOODSDETAILINFO(state,goodsDetailInfo){
        state.goodsDetailInfo=goodsDetailInfo
    }
}
const actions ={
    //请求获取商品详情信息
    async getGoodsDetailInfo({commit},skuId){
        const result = await reqGoodsDetailInfo(skuId)
        if(result.code===200){
            commit('RECEIVE_GOODSDETAILINFO',result.data)
        }
    }
}
const getters ={
    categoryView(state){
        return state.goodsDetailInfo.categoryView || {}
    },
    skuInfo(state){
        return state.goodsDetailInfo.skuInfo || {}
    },
    spuSaleAttrList(state){ 
        return state.goodsDetailInfo.spuSaleAttrList || []
    }
}

export default {
    state,
    mutations,
    actions,
    getters,
}